home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
PredatorPrey
/
calc_mousedown.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
33KB
|
1,134 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Prototype HP15C Calculator */
/* James C. Ullrey */
/* INRESCO */
/* © 1990 */
/* Version 13.97a */
/* */
/* MOUSEDOWN SEGMENT */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/*****************************************************************/
/* I N C L U D E S
/*****************************************************************/
#include "EditM.h"
#ifndef __C14__
#include "PredatorPrey.h"
#endif
#include <Processes.h>
#include "windows.h"
#include "calc_contents.h"
#include "calc_controls.h"
#include "ResourceDefs.h"
#include "calc_dork.h"
#include "Globals.h"
#include "HelpGetProc.h"
#include "ProgramM.h"
#include "ProgramWindow.h"
#include "Windowing.h"
#include "YEquals.h"
#include "ZoomM.h"
#include "PlotM.h"
#include <EPPC.h>
#include <PPCToolbox.h>
#include <AppleEvents.h>
#include <Aliases.h>
#include <Files.h>
#include <Dialogs.h>
#include "DialogAids.h"
#ifndef __CIN__
#include "calc_inits.h"
#endif
#include "calc_update.h"
#include "calc_files.h"
#include "calc_mousedown.h"
#include "calc_handlebutton.h"
#include "create_prey.h"
/********************************************************************
/* G L O B A L V A R I A B L E D E C L A R A T I O N S
/********************************************************************/
#define kFinderType 'FNDR'
#define kSysCreator 'MACS'
#define kAEOpenSelection 'sope'
#define aeSelectionKeyword 'fsel'
#define localLaunch 1
#define localWindow 2
#define remoteLaunch 3
#define kResumeMask 1 /* bit of message field for resume vs. suspend */
#define kTextType 'TEXT'
#define kTextResID 128
#define kPathDialog 133
#define kEditLineItem 4
#define kColon ':'
enum
{
kGenStrings = 128, kPPCPrompt1 = 1, kPPCPrompt2
};
EventRecord gERecord; /* EventRecord */
//#define DEBUGGING TRUE
extern Boolean scrapDirty;
//extern WindowPtr theWPtr;
extern Boolean Transmogrified;
extern Boolean Iconized;
extern Boolean oldWay;
extern short gErrorFlag;
extern short ErrorZero;
extern short ErrorOne;
extern short ErrorTwo;
extern short ErrorThree;
extern short ErrorFour;
extern short ErrorFive;
extern short ErrorSix;
extern short ErrorSeven;
extern short ErrorEight;
extern short ErrorNine;
extern short ErrorTen;
extern short ErrorEleven;
extern long gState;
extern long delayTime;
extern long gsState;
extern long sto;
extern long rcl;
extern long gNewNum;
/*extern long canClear;*/
extern long gRoll;
extern long wait;
extern long gFlag;
extern long fFlag;
extern long sWait;
extern long rWait;
extern long lblWait;
extern long plus;
extern long minus;
extern long timesF;
extern long divide;
extern long gDot;
/*extern long rsFlag;*/
extern long gDigits;
/*extern long runMode;*/
/*extern long gsbWait;*/
extern long gtoWait;
extern short sRefNum;
extern short rRefNum;
extern short qRefNum;
extern short pRefNum;
extern short gWindowState;
extern short gMatWin;
extern short gRegWin;
extern short gProgWin;
extern Rect gDragRect;
extern Rect gNoColorDragRect;
extern Boolean gLoadProgEnabled;
extern Str255 theFrogName;
extern /*static*/ short theVRefNum;
extern WindowPtr lastPtr;
extern Boolean gIsWizard;
extern Boolean stillWizard;
extern Boolean hasPlot;
extern short kNumMyHelpItems;
/*****************************************************************/
/* P R O T O T Y P E S
/*****************************************************************/
void TimingLoop (void);
void HandleAppleChoice (short theItem);
void HandleFileChoice (short theItem);
void HandleEditChoice (short theItem);
void HandleWindowChoice (short theItem);
void HandleProgramChoice (short theItem);
void HandleGraphChoice (short theItem);
void HandleGraphSubChoice (short theItem);
void HandleDorkChoice ( short theItem );
void HandlePlotChoice ( short theItem );
void MyHandleHelpCommand(short theItem );
//extern Rect *WinRect ( WindowPtr wptr, Rect *scrRect );
//extern void DoKiller (void);
//extern WindowPtr get_window (short selector);
//extern WindowPtr get_rotation_box (void);
//extern WindowPtr get_stretch_box (void);
//extern void do_grow (WindowPtr wPtr, Point global_pt);
OSErr FindAProcess (
OSType typeToFind,OSType creatorToFind,
ProcessSerialNumberPtr processSN,
ProcessInfoRecPtr infoRecToFill
);
pascal Boolean idleProc (EventRecord *eventIn, long *sleep, RgnHandle *mouseRgn);
pascal Boolean FinderFilter (LocationNamePtr locationName, PortInfoPtr thePortInfo);
OSErr GetPathAndName (Str255 fullPath, Str255 appName);
void DrawMain (WindowPtr drawIt);
ControlHandle SnatchHandle (DialogPtr thebox, short theGetItem);
static void DoUndo (void);
static void DoCut (void);
static void DoCopy (void);
static void DoPaste (void);
static void DoClear (void);
/*****************************************************************/
/*****************************************************************/
/* */
/* R O U T I N E S */
/* */
/*****************************************************************/
/*****************************************************************/
void mousedown_seg() {} /* for reference in "UnloadSeg()" calls */
/*----------*/
/*static void DoYEquals(void)*/
/*{*/
/* YEqualsRec YEqualsInfo;*/
/* register YEqualsRecPtr info;*/
/**/
/* info = &YEqualsInfo;*/
/* /*initialize AddC info»*/
/* info->Field7Text [0] = 0;*/
/* info->Field8Text [0] = 0;*/
/* info->Field13Text [0] = 0;*/
/* info->List9Choice = -1;*/
/* */
/* if (GetYEquals (&YEqualsInfo)) { /* in YEquals.c »*/
/* /*use YEquals info»*/
/* }*/
/*}*/ /*DoYEquals*/
/********************** TimingLoop ************************/
void TimingLoop()
{
long first;
long second;
long delayTime = 6;
if(Transmogrified)
{
first = delayTime;
}
else
{
first = 6;
}
#ifdef fast
#else
Delay(first,&second);
#endif
}
/********************** HandleMouseDown ************************/
void HandleMouseDown()
{
WindowPtr whichWindow;
short thePart,control_part;
long menuChoice;
long windSize,dummy;
long startTick1,stopTick1,startTick2,stopTick2;
long oldTime,newTime;
short myItemHit;
short calcCol,calcRow;
Point myPoint;
GrafPtr oldPort;
Point pt,pt2;
Rect scrRect;
Point where;
ControlHandle cntl_hndl;
WRObjsHandle wr_objs_hndl;
WSObjsHandle ws_objs_hndl;
thePart = FindWindow( gTheEvent.where, &whichWindow );
switch ( thePart )
{
case inMenuBar :
menuChoice = MenuSelect( gTheEvent.where );
HandleMenuChoice( menuChoice );
break;
case inSysWindow : /* By clicking Apple icon and dragging to DA */
SystemClick( &gTheEvent, whichWindow );
break;
case inDrag :
DragWindow( whichWindow, gTheEvent.where, &gDragRect );
break;
case inGrow:
if ( one_of_mine(whichWindow) )
{
do_grow(whichWindow, gTheEvent.where); /* calc_update.c */
}
break;
case inGoAway :
if (TrackGoAway(whichWindow, gTheEvent.where))
{
if ( one_of_mine(whichWindow) )
{
save_window(whichWindow); /* in calc_files.c */
}
else if(whichWindow == gRotateBox)
{
wr_objs_hndl = (WRObjsHandle)GetWRefCon(gRotateBox);
if(wr_objs_hndl != NIL)
{
HLock((Handle)wr_objs_hndl);
/*if((**wr_objs_hndl).prInfoHndl) DisposHandle((**wr_objs_hndl).prInfoHndl);*/
DisposHandle((Handle)wr_objs_hndl);
}
DisposeWindow(gRotateBox); /* also does a "KillControls()" */
gRotateBox = NIL;
EnableItem(GetMHandle(DORK_MENU_ID), 2);
}
else if(whichWindow == gStretchBox)
{
ws_objs_hndl = (WSObjsHandle)GetWRefCon(gStretchBox);
if(ws_objs_hndl != NIL)
{
HLock((Handle)ws_objs_hndl);
/*if((**ws_objs_hndl).prInfoHndl) DisposHandle((**ws_objs_hndl).prInfoHndl);*/
DisposHandle((Handle)ws_objs_hndl);
}
DisposeWindow(gStretchBox); /* also does a "KillControls()" */
gStretchBox = NIL;
EnableItem(GetMHandle(DORK_MENU_ID), 3);
}
}
/*gDone = TRUE;*/
break;
case inContent :
if ( one_of_mine(whichWindow) )
{
if (whichWindow != FrontWindow())
SelectWindow( whichWindow );
else
{
SetPort(whichWindow);
myPoint = gTheEvent.where;
GlobalToLocal(&myPoint);
if((control_part = FindControl(myPoint, whichWindow, &cntl_hndl)))
{
do_controls(myPoint, whichWindow, cntl_hndl, control_part);
}
else
{
draw_contents(whichWindow, &gTheEvent); /* in calc_contents.c */
}
}
}
else if ( whichWindow == gStretchBox )
{
if (whichWindow != FrontWindow())
SelectWindow( whichWindow );
do_stretch_box(whichWindow,&gTheEvent); /* in calc_contents.c */
}
else if ( whichWindow == gRotateBox )
{
if (whichWindow != FrontWindow())
SelectWindow( whichWindow );
do_rotate_box(whichWindow,&gTheEvent); /* in calc_contents.c */
}
else
{
DoKiller();
}
break;
}
} /* calc_mousedown.c */
/******************* end of HandleMouseDown *********************/
/********************** HandleMenuChoice ************************/
void HandleMenuChoice(long menuChoice )
{
short theMenu;
short theItem;
if ( menuChoice != 0 )
{
theMenu = HiWord( menuChoice );
theItem = LoWord( menuChoice );
switch ( theMenu )
{
case APPLE_MENU_ID :
HandleAppleChoice( theItem );
break;
case FILE_MENU_ID :
HandleFileChoice( theItem/*, &theFileName, &theVRefNum */);
break;
case EDIT_MENU_ID :
/*HandleEditChoice( theItem );*/
DoEdit( theItem );
break;
// case WINDOW_MENU_ID :
// HandleWindowChoice( theItem );
// break;
// case PROGRAM_MENU_ID :
// HandleProgramChoice( theItem );
// break;
case GRAPHICS_MENU_ID:
HandleGraphChoice( theItem );
break;
case GRAPHICS_SUBMENU_ID:
HandleGraphSubChoice( theItem );
break;
case DORK_MENU_ID:
HandleDorkChoice( theItem );
break;
/*case PLOT_MENU_ID:*/
/*HandlePlotChoice( theItem );*/
/*break;*/
// case PlotID:
// DoPlot( theItem );
// break;
// case ZoomID:
// DoZoom ( theItem );
// break;
// case WizardMenuID:
// DoWizardMenu( theItem );
// break;
case PreyMenuID:
DoPreyMenu( theItem );
break;
// case kHMHelpMenuID:
// MyHandleHelpCommand( theItem );
// break;
}
}
HiliteMenu( 0 );
}
/********************** HandleAppleChoice ************************/
void HandleAppleChoice(short theItem )
//short theItem;
{
Str255 accName;
short accNumber;
short itemNumber;
switch ( theItem )
{
case ABOUT_ITEM_ID :
NoteAlert( ABOUT_ALERT, NIL_POINTER );
break;
// case HELP_ITEM :
// /*HelpGetProc();*/
// GetHelp(); /* in calc_help.c */
// break;
// case ALT_HELP_ITEM:
// if(TRUE)
// {
// HelpGetProc();
// }
// else
// {
// GetFooling();
// }
// break;
default :
GetItem( gAppleMenu, theItem, accName );
accNumber = OpenDeskAcc( accName );
break;
}
}
/********************** HandleFileChoice ************************/
void HandleFileChoice(short theItem/*, fn, refNum*/ )
//short theItem;
/*Str255 *fn;*/
/*int *refNum;*/
{
Str255 theLogFileName = "\pHP15C_Log";
Str255 theOtherLogFileName = "\pHP15C_Log_2";
WindowPtr whichWindow;
Str255 timeString;
long countDownTime;
short itemType;
Rect itemRect;
OSErr error;
Handle itemHandle;
long count,fcount;
Boolean checkIt;
static short logState;
count = sizeof(map);
fcount = sizeof(frog);
switch ( theItem )
{
case OPEN_DATA_FILE_ITEM : /* Item 1 */
DisableItem(GetMHandle(FILE_MENU_ID), 1); /* Open Calculator */
EnableItem(GetMHandle(FILE_MENU_ID), 2); /* Save Data */
EnableItem(GetMHandle(FILE_MENU_ID), 3); /* Save Program */
EnableItem(GetMHandle(FILE_MENU_ID), 4); /* New Program */
if(gLoadProgEnabled)
{
DisableItem(GetMHandle(FILE_MENU_ID), 5); /* CLOSE_PROGRAM */
EnableItem(GetMHandle(FILE_MENU_ID), 6); /* LOAD_PROGRAM */
}
else
{
EnableItem(GetMHandle(FILE_MENU_ID), 5); /* CLOSE_PROGRAM */
DisableItem(GetMHandle(FILE_MENU_ID), 6); /* LOAD_PROGRAM */
}
DisableItem(GetMHandle(FILE_MENU_ID), 7); /* LOAD_DATA */
EnableItem(GetMHandle(FILE_MENU_ID), 8); /* CLOSE_CALCULATOR */
//EnableItem(GetMHandle(WINDOW_MENU_ID), 1);
//EnableItem(GetMHandle(WINDOW_MENU_ID), 2);
//EnableItem(GetMHandle(PROGRAM_MENU_ID), 1);
//EnableItem(GetMHandle(PROGRAM_MENU_ID), 2);
break;
case SAVE_DATA_FILE_ITEM : /* Item 2 */
if(gIsWizard)
{
/*StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);*/
DoWizSaveData();
}
else
{
error = SetFPos(qRefNum,1,0); /* II-93, IV-110 */
error = FSWrite(qRefNum,&count,&map); /* II-92, IV-110 */
error = FlushVol(NIL,theVRefNum);
}
break;
case CLOSE_ITEM : /* Item 3 */
break;
// case NEW_PROGRAM_ITEM: /* Item 4 */
// if(gIsWizard)
// {
// #ifdef powerc
// StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);
// #else
// StopAlert (UNDER_CONSTRUCTION, NIL);
// #endif /* powerc */
// DoWizNew();
// }
// break;
//
// case CLOSE_PROGRAM_ITEM : /* Item 5 */
// if(gIsWizard)
// {
// /*StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);*/
// DoWizClose();
// }
// else
// {
// error = SetFPos(pRefNum,1,0);
// error = FSWrite(pRefNum,&fcount,&frog);
// error = FSClose(pRefNum);
// error = FlushVol(NIL,theVRefNum);
// if(!error)
// {
// gLoadProgEnabled = TRUE;
// DisableItem(GetMHandle(FILE_MENU_ID), 5);
// EnableItem(GetMHandle(FILE_MENU_ID), 6);
// }
// }
// break;
// case LOAD_PROGRAM_ITEM : /* Item 6 */
// if(gIsWizard)
// {
// /*StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);*/
// DoWizOpenProg();
// }
// else
// {
// error = FSOpen(theFrogName, theVRefNum, &pRefNum);
// if(error == opWrErr)
// {
// Alert(FILE_OPEN,NIL);
// }
// else if(error == fnfErr || error == bdNamErr)
// {
// Alert(NO_FILE,NIL);
// }
// else
// {
// error = SetFPos(pRefNum,1,0); /* II-93, IV-110 */
// error = FSRead(pRefNum,&fcount,&frog); /* II-92, IV-109 */
// if(!error)
// {
// gLoadProgEnabled = FALSE;
// EnableItem(GetMHandle(FILE_MENU_ID), 5); /* CLOSE_PROGRAM */
// DisableItem(GetMHandle(FILE_MENU_ID), 6); /* LOAD_PROGRAM */
// }
// }
// }
// break;
// case LOAD_DATA_ITEM : /* Item 7 */
// if(gIsWizard)
// {
// /*StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);*/
// DoWizOpenData();
// }
// else
// {
// #ifdef powerc
//
// //StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);
// #else
// //DoBremOpenData();
// //StopAlert (UNDER_CONSTRUCTION, NIL);
// #endif /* powerc */
// }
// break;
// case CLOSE_ITEM : /* Item 8 */
// if ( ( whichWindow = FrontWindow() ) != NIL_POINTER && whichWindow == gCalcWindow )
// {
// DiscardInfo ( whichWindow );
// //DisposeWindow( whichWindow );
// DisposeWindow( gSRegWindow );
// DisposeWindow( gMatEWindow );
// DisposeWindow( gMatDWindow );
// DisposeWindow( gMatCWindow );
// DisposeWindow( gMatBWindow );
// DisposeWindow( gMatAWindow );
// if(gWindowState & gProgWin)
// {
// gWindowState ^= gProgWin;
// checkIt = FALSE;
// CheckItem(GetMenu(PROGRAM_MENU_ID),PROGRAM_ITEM,checkIt);
// DisableItem(GetMHandle(PROGRAM_MENU_ID), 2);
// if(whichWindow != gProgWindow)
// {
// SelectWindow(gProgWindow);
// SetInfo(gProgWindow);
// }
// CloseProgramWindow();
// }
// gWindowState |= gMatWin;
// gWindowState ^= gMatWin;
// checkIt = FALSE;
// CheckItem(GetMenu(WINDOW_MENU_ID),MATRIX_ITEM,checkIt);
// gWindowState |= gRegWin;
// gWindowState ^= gRegWin;
// gWindowState |= gProgWin;
// gWindowState ^= gProgWin;
// CheckItem(GetMenu(WINDOW_MENU_ID),REGISTER_ITEM,checkIt);
// CheckItem(GetMenu(PROGRAM_MENU_ID),PROGRAM_ITEM,checkIt);
// CheckItem(GetMenu(PROGRAM_MENU_ID),DISASSEMBLE_ITEM,checkIt);
// EnableItem(GetMHandle(FILE_MENU_ID), 1); /* Open Calculator */
// DisableItem(GetMHandle(FILE_MENU_ID), 2); /* Save Data */
// DisableItem(GetMHandle(FILE_MENU_ID), 3); /* Save Program */
// DisableItem(GetMHandle(FILE_MENU_ID), 4); /* New Program */
// DisableItem(GetMHandle(FILE_MENU_ID), 5); /* CLOSE_PROGRAM */
// DisableItem(GetMHandle(FILE_MENU_ID), 6); /* LOAD_PROGRAM */
// DisableItem(GetMHandle(FILE_MENU_ID), 7); /* LOAD_DATA */
// DisableItem(GetMHandle(FILE_MENU_ID), 8); /* CLOSE_CALCULATOR */
// DisableItem(GetMHandle(WINDOW_MENU_ID), 1);
// DisableItem(GetMHandle(WINDOW_MENU_ID), 2);
// DisableItem(GetMHandle(PROGRAM_MENU_ID), 1);
// DisableItem(GetMHandle(PROGRAM_MENU_ID), 2);
// }
// /* else if( ( whichWindow = FrontWindow() ) != NIL_POINTER && whichWindow == gCalcWindow ) */
// break;
case QUIT_ITEM : /* Item 4 */
error = SetFPos(qRefNum,1,0); /* II-93, IV-110 */
error = FSWrite(qRefNum,&count,&map); /* II-92, IV-110 */
error = FSClose(qRefNum); /* II-94, IV-112 */
error = SetFPos(pRefNum,1,0);
error = FSWrite(pRefNum,&fcount,&frog);
error = FSClose(pRefNum);
error = FlushVol(NIL,theVRefNum);
if(!error);
else
{
/*DebugStr("\pHello from FSWrite error")*/;
}
DisposeRgn(workRegionH); /* release region for TE redraw */
/*FlushVol();*/
gDone = TRUE;
break;
}
}
/********************** HandleEditChoice ************************/
void HandleEditChoice(short theItem )
{
//SystemEdit( theItem - 1 );
switch (theItem)
{
case EditUndo:
DoUndo ();
break;
case EditCut:
DoCut ();
break;
case EditCopy:
DoCopy ();
break;
case EditPaste:
DoPaste ();
break;
case EditClear:
DoClear ();
break;
}
}
/*********************** HandleGraphSubChoice ***********************/
void HandleGraphSubChoice(short theItem )
{
WindowPtr wPtr;
short i;
/*static Boolean hasPlot;*/
switch ( theItem )
{
case NEW_GRAPHICS_WINDOW:
break;
}
}
/*********************** HandleGraphChoice ***********************/
void HandleGraphChoice(short theItem )
//short theItem;
{
WindowPtr wPtr;
short i;
switch ( theItem )
{
case OPEN_GRAPHICS_WINDOW:
if((wPtr = get_window(1)) != NIL) /* get_window() ; in calc_inits.c */
{
if(gIsWizard)
{
PreyMenu = GetMenu(PreyMenuID);
InsertMenu(PreyMenu,0);
DrawMenuBar();
}
ShowWindow(wPtr);
SelectWindow(wPtr);
lastPtr = wPtr;
}
break;
}
}
/*********************** HandleDorkChoice ************************/
void HandleDorkChoice(short theItem ) /* menu name is Stretch&Rotate */
//short theItem;
{
DialogPtr dStrPtr,dRotPtr;
WindowPtr wPtr;
GrafPtr oldPort;
long ticktime;
double_t delX;
double_t delY;
double_t delZ;
static Boolean useCalc;
Boolean checkIt,fineMove = false;
WRObjsHandle wr_objs_hndl;
OSErr iErr;
OSErr interactErr = noErr;
LocationNameRec theLocation;
PortInfoRec thePortInfo;
TargetID theID;
AEDesc myAddressDesc;
AppleEvent aeEvent, aeReply;
FSSpecPtr theFileToOpen = nil;
FSSpec dirSpec, procSpec;
AliasHandle DirAlias, FileAlias;
ProcessSerialNumber process;
ProcessInfoRec infoRec;
StandardFileReply myReply;
Str31 processName;
AEDesc aeDirDesc, listElem;
AEDesc fileList;
Str255 tWext;
Str255 t2Wext;
short which,i;
PPCFilterUPP myPPCFilter; /* mine */
AEIdleUPP myIdleProcPtr; /* mine */
Str255 fullPath;
Str255 appName;
unsigned char appName2[254];
wPtr = FrontWindow();
if(one_of_mine(wPtr) )
{
switch ( theItem )
{
case ROTATION_BOX:
if((gRotateBox = get_rotation_box()) != NIL) /* get_rotation_box() ; in calc_inits.c */
{
DisableItem(GetMHandle(DORK_MENU_ID), 1);
ShowWindow(gRotateBox);
SelectWindow(gRotateBox);
wr_objs_hndl = (WRObjs**)GetWRefCon(gRotateBox);
(**wr_objs_hndl).paletteSetting = 0;
do_rotation_subject(gRotateBox,fineMove); /* in calc_contents.c */
}
break;
case STRETCH_BOX:
if(( gTheEvent.modifiers & optionKey ) != 0) /* (gTheEvent.modifiers & optionKey) */
{ /* (gTheEvent.modifiers & alphaLock) */
if(gTheEvent.modifiers & cmdKey) which = remoteLaunch; /* (gTheEvent.modifiers & cmdKey) */
if(gTheEvent.modifiers & controlKey) which = localLaunch; /* (gTheEvent.modifiers & controlKey) */
if(gTheEvent.modifiers & shiftKey) which = localWindow; /* (gTheEvent.modifiers & shiftKey) */
if (which != remoteLaunch)
StandardGetFile(nil, -1, nil, &myReply);
else
myReply.sfGood = true;
if (myReply.sfGood)
{
theFileToOpen = &myReply.sfFile;
infoRec.processInfoLength = sizeof(ProcessInfoRec);
infoRec.processName = &processName[0];
infoRec.processAppSpec = &procSpec;
if (which != remoteLaunch)
{
iErr = FindAProcess(kFinderType, kSysCreator, &process, &infoRec);
//#ifdef DEBUGGING
// DebugStr("\pRight after FindAProcess");
//#endif
if (iErr == noErr)
iErr = AECreateDesc(typeProcessSerialNumber, (Ptr)&process, sizeof(process), &myAddressDesc);
//#ifdef DEBUGGING
// DebugStr("\pRight after AECreateDesc");
//#endif
}
else
{
GetIndString(tWext, kGenStrings, kPPCPrompt1);
GetIndString(t2Wext, kGenStrings, kPPCPrompt2);
myPPCFilter = NewPPCFilterProc((PPCFilterProcPtr)FinderFilter); /* mine */
iErr = PPCBrowser (
tWext,
t2Wext,
FALSE,
&theLocation,
&thePortInfo,
myPPCFilter, /*(PPCFilterProcPtr)FinderFilter, <-- the way it came */
NIL /* theLocNBPType = */
);
if (iErr == noErr)
{
theID.name = thePortInfo.name;
theID.location = theLocation;
iErr = AECreateDesc(typeTargetID, (Ptr)&theID, sizeof(theID), &myAddressDesc);
}
}
if (iErr == noErr)
/************/ {
iErr = AECreateAppleEvent (
kFinderType, kAEOpenSelection,
&myAddressDesc, kAutoGenerateReturnID,
kAnyTransactionID, &aeEvent
);
AEDisposeDesc(&myAddressDesc);
//#ifdef DEBUGGING
// DebugStr("\pRight after AECreateAppleEvent");
//#endif
if (iErr == noErr)
{
if(which != remoteLaunch)
{
iErr = FSMakeFSSpec(theFileToOpen->vRefNum, theFileToOpen->parID, nil, &dirSpec);
NewAlias(nil, &dirSpec, &DirAlias);
}
switch (which)
{
case localLaunch:
NewAlias(nil, theFileToOpen, &FileAlias);
//#ifdef DEBUGGING
// DebugStr("\pRight after NewAlias");
//#endif
break;
case localWindow:
NewAlias(nil, &dirSpec, &FileAlias);
//myIdleProcPtr = NewAEIdleProc((IdleProcPtr)idleProc);
myIdleProcPtr = NewAEIdleProc((ProcPtr)idleProc);
//interactErr = AEInteractWithUser(kAEDefaultTimeout, nil, (IdleProcPtr)idleProc);
interactErr = AEInteractWithUser(kAEDefaultTimeout, nil, myIdleProcPtr);
if (interactErr == noErr)
SetFrontProcess(&process);
break;
case remoteLaunch:
iErr = GetPathAndName(fullPath, appName);
if (iErr == noErr)
{
/* NewAliasMinimalFromFullPath (geez what a lot of typing) creates an alias that does NOT */
/* have a file ID, just builds based on what it has, the path. So we don't need to */
/* connect to another machine or file server to make this alias, which is why this thing works. */
// for(i = 1;i <= appName[0];i++)
// {
// appName2[i] = appName[i];
// }
// NewAliasMinimalFromFullPath(appName[0], &appName2[1], "", "", &FileAlias);
NewAliasMinimalFromFullPath(appName[0], &appName[1], "\p", "\p", &FileAlias);
/* NewAliasMinimalFromFullPath(fullPath[0], (Ptr)&fullPath[1], "", "", &DirAlias); old way */
NewAliasMinimalFromFullPath(fullPath[0], &fullPath[1], "\p", "\p", &DirAlias);
}
break;
}
if (iErr == noErr)
{
iErr = AECreateList(nil, 0, false, &fileList);
/* create the folder descriptor */
HLock((Handle)DirAlias);
AECreateDesc(typeAlias, (Ptr)*DirAlias, GetHandleSize((Handle)DirAlias), &aeDirDesc);
HUnlock((Handle)DirAlias);
if ((iErr = AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) == noErr)
{
/* done with the desc, kill it */
AEDisposeDesc(&aeDirDesc);
/* create the file descriptor and add to aliasList */
HLock((Handle)FileAlias);
AECreateDesc(typeAlias, (Ptr)*FileAlias, GetHandleSize((Handle)FileAlias), &listElem);
HLock((Handle)FileAlias);
iErr = AEPutDesc(&fileList, 0, &listElem);
}
if (iErr == noErr)
{
AEDisposeDesc(&listElem);
/* Add the file alias list to the event */
iErr = AEPutParamDesc(&aeEvent, aeSelectionKeyword, &fileList);
AEDisposeDesc(&fileList);
if (iErr == noErr)
iErr = AESend(&aeEvent, &aeReply, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
}
}
AEDisposeDesc(&aeEvent);
}
}
}
if ((Handle)DirAlias)
DisposHandle((Handle)DirAlias);
if ((Handle)FileAlias)
DisposHandle((Handle)FileAlias);
}
else if((gStretchBox = get_stretch_box()) != NIL) /* get_stretch_box() ; in calc_inits.c */
{
DisableItem(GetMHandle(DORK_MENU_ID), 2);
ShowWindow(gStretchBox);
SelectWindow(gStretchBox);
do_stretch_subject(gStretchBox);
}
break;
}
}
else
{
#ifdef powerc
StopAlert (NOT_GRAPHICS_WINDOW, (UniversalProcPtr)NIL);
#else
StopAlert (NOT_GRAPHICS_WINDOW, NIL);
#endif /* powerc */
}
}
/********************* MyHandleHelpCommand ***********************/
void MyHandleHelpCommand(short theItem )
{
MenuHandle myHelpMenuHandle;
short origHelpItems, numItems;
short gMyHelpItem1,gMyHelpItem2;
OSErr myErr;
myErr = HMGetHelpMenuHandle(&myHelpMenuHandle);
if(myErr == noErr)
{
numItems = CountMItems(myHelpMenuHandle);
origHelpItems = numItems - kNumMyHelpItems;
if(theItem > origHelpItems)
{
gMyHelpItem1 = origHelpItems + 3;
gMyHelpItem2 = origHelpItems + 4;
if(theItem == gMyHelpItem1)
{
//GetHelp();
}
else if(theItem == gMyHelpItem2)
{
HelpGetProc();
}
/*MyHelp(theItem);*/
}
}
}
/* Show only FInders */
pascal Boolean FinderFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo)
{
#pragma unused (locationName)
OSType type;
if (thePortInfo->name.portKindSelector == ppcByString) {
BlockMove(thePortInfo->name.u.portTypeStr + 1, (Ptr)&type, 4);
/* The BlockMove is so that we don't get an address error
** on a 68000-based machine due to referencing a long at
** an odd-address. */
if (type == kSysCreator)
return(true);
}
return(false);
}
pascal Boolean idleProc(EventRecord *eventIn, long *sleep, RgnHandle *mouseRgn)
{
Boolean gInBackground;
switch (eventIn->what) {
case nullEvent:
/* no nul processing in this sample */
*sleep = 0;
mouseRgn = nil;
break;
case updateEvt:
case activateEvt:
DrawMain((WindowPtr)eventIn->message); /* draw whatever window needs an update */
break;
case app4Evt:
switch ((gERecord.message >> 24) & 0x0FF) { /* high byte of message */
case suspendResumeMessage: /* suspend/resume is also an activate/deactivate */
gInBackground = (gERecord.message & kResumeMask) == 0;
break;
}
break;
}
return(false); /* I'll wait forever */
}
void DrawMain(WindowPtr drawIt)
{
Handle theText;
BeginUpdate(drawIt);
SetPort(drawIt);
EraseRect(&drawIt->portRect);
theText = GetResource(kTextType, kTextResID);
if (theText) {
Rect textRect;
HLock(theText);
HUnlock(theText);
textRect = drawIt->portRect;
InsetRect(&textRect, 5, 5);
TextBox(*theText, GetHandleSize(theText), &textRect, 0);
ReleaseResource(theText);
}
EndUpdate(drawIt);
}
OSErr GetPathAndName(Str255 fullPath, Str255 appName)
{
DialogPtr tdial = GetNewDialog(kPathDialog, nil, (WindowPtr)-1);
short hitItem = 0;
Str255 tempString;
short where;
// ModalFilterUPP gMyStandardFilterUPP;
// ModalFilterProcPtr filterIt = nil;
ModalFilterUPP filterIt = nil;
OSErr retVal = userCanceledErr;
SetDialogDefaultItem(tdial, ok);
SetDialogCancelItem(tdial, cancel);
SetDialogTracksCursor(tdial, true);
filterIt = NewModalFilterProc(filterIt);
//gMyStandardFilterUPP = NewModalFilterProc(gMyStandardFilterUPP); /* new */
GetStdFilterProc(&filterIt);
ShowWindow(tdial);
DrawDialog(tdial);
do {
//ModalDialog((ModalFilterProcPtr)filterIt, &hitItem);
ModalDialog(/*(ModalFilterUPP)gMyStandardFilterUPP*/nil, &hitItem);
}
while (hitItem != ok && hitItem != cancel);
if (hitItem == ok) {
GetIText((Handle)SnatchHandle(tdial, kEditLineItem), tempString);
/* now parse backwards to find the last colon, which is seperating the file name from the path */
where = tempString[0];
while (tempString[where] != kColon && where > 0)
where--;
if (where > 0) {
BlockMove((Ptr)&tempString[0], (Ptr)&appName[0], tempString[0] + 1);
BlockMove((Ptr)&tempString[0], (Ptr)&fullPath[0], where + 1); /* include the colon */
fullPath[0] = where;
retVal = noErr;
}
}
DisposDialog(tdial);
return(retVal);
}
ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
{
short itemtype;
Rect itemrect;
Handle thandle;
GetDItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
return((ControlHandle)thandle);
}
/* end SnatchHandle */
OSErr FindAProcess(OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN, ProcessInfoRecPtr infoRecToFill)
{
ProcessSerialNumber tempPSN;
OSErr myErr = noErr;
tempPSN.lowLongOfPSN = kNoProcess;
processSN->lowLongOfPSN = kNoProcess;
processSN->highLongOfPSN = kNoProcess;
do {
myErr = GetNextProcess(processSN);
if (myErr == noErr)
GetProcessInformation(processSN, infoRecToFill);
}
while ((infoRecToFill->processSignature != creatorToFind || infoRecToFill->processType != typeToFind) ||
myErr != noErr);
return(myErr);
}